package com.allwees.core.common.util.freemarker;

import freemarker.template.Configuration;
import freemarker.template.Template;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;

@Slf4j
@Component
public class FreeMarkerUtil {

    @Autowired
    private Configuration configuration;

    public String render(String path, Object obj) {
        Template template;
        try {
            template = configuration.getTemplate(path);
            return FreeMarkerTemplateUtils.processTemplateIntoString(template, obj);
        } catch (Exception e) {
            log.error("getContentForFtl error ", e);
        }
        return null;
    }
}
